<?php

namespace common\models\business;

use Yii;

/**
 * This is the model class for table "business_growup".
 *
 * @property string $id
 * @property integer $pigid
 * @property integer $person
 * @property string $reason
 * @property string $descripation
 * @property integer $createtime
 * @property integer $killtype
 * @property string $killprice
 */
class BusinessGrowup extends \yii\db\ActiveRecord
{
    //主要用于日志记录
    public $uselog = [
        'tabcomment' => '宰杀订单',      //用于修改了什么的显示
        'mainfield' => 'ordersn',      //主要的显示标题的字段
        'picturefield' => [],        //图片字段
        'timefield' => ['paytime'],       //时间字段
        'unsetfiled' =>[],      //不需要记录的字段
    ];

    //-2支付失败  -1取消状态，0普通状态，1为已付款，2为待入住，3为已入住，4订单完结(已评价)
    const STATUS_PAYFAIL = -2;
    const STATUS_CANCAL = -1;
    const STATUS_MANAL = 0;
    const STATUS_PAY = 1;
    const STATUS_WAITGET = 2;
    const STATUS_CONFIRMGET = 3;
    public static $statues = [
        self::STATUS_PAYFAIL => '支付失败',
        self::STATUS_CANCAL => '取消',
        self::STATUS_MANAL => '待支付',
        self::STATUS_PAY => '已付款'
    ];

    const WECHAT_PAY = 1;
    const NO_PAY = 0;
    public static $paytype = [
        self::WECHAT_PAY => '微信支付',
        self::NO_PAY => '未支付',
    ];


    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'business_growup';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id', 'pigid', 'person', 'reason', 'createtime', 'killtype', 'killprice'], 'required'],
            [['id', 'pigid', 'person', 'createtime','userid','status','paytype'], 'integer'],
            [['killprice'], 'number'],
            [['reason', 'descripation','pigno','transid'], 'string', 'max' => 255],
            [['pigno','ordersn','killtype'], 'string', 'max' => 50],
            [['paydetail'], 'string', 'max' => 2000],
            [['paytime'], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'pigid' => '仔猪id',
            'pigno' => '仔猪编号',
            'person' => '出栏操作人',
            'reason' => '出栏原因',
            'descripation' => '出栏详细描述',
            'createtime' => '创建时间',
            'killtype' => '宰杀方式',
            'killprice' => '宰杀价格',
            'ordersn' => '宰杀订单编号',
            'userid'=>'支付人',
            'transid' => '微信支付流水',
            'status' => '状态',
            'paytime' => '支付时间',
            'paytype' => "支付方式",
        ];
    }


    public function getUser()
    {
        return $this->hasOne(BusinessUser::className(),['id'=>'userid']);
    }

    public function getPersona()
    {
        return $this->hasOne(BusinessPerson::className(),['id'=>'person']);
    }
}
